﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using EvincePayroll.Data;
using EvincePayroll.Logic;
using EvincePayroll.Utility;

namespace Evince.Service
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class UserRoleService
    {

        [WebGet(UriTemplate = "GetUserRoleList/{email}")]
        public List<UserRoleData> GetUserRoleList(string email)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(email);
                return userRoleLogic.GetUserRoleList(email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "CreateRole/{email},{RoleName}")]
        public bool CreateRole(string email, string RoleName)
        {
            try
            {
                EmployeeLogic role = new EmployeeLogic(email);
                return role.CreateRole(email, RoleName);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetAllUserRole/{email}")]
        public List<UserRoleData> GetAllUserRole(string email)
        {
            try
            {
                EmployeeLogic role = new EmployeeLogic(email);
                return role.GetAllUserRole(email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "DeleteRole/{userId}")]
        public bool DeleteRole(string userId)
        {
            try
            {
                UserRoleLogic role = new UserRoleLogic(userId);
                return role.DeleteRole(userId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "UpdateRoleAccess/{menuId},{roleId},{sortOrder},{parentId}")]
        public bool UpdateRoleAccess(string menuId, string roleId, string sortOrder, string parentId)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(menuId);
                return userRoleLogic.UpdateRoleAccess(menuId, roleId, sortOrder, parentId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebGet(UriTemplate = "DeleteRoleAccess/{menuId},{roleId}")]
        public bool DeleteRoleAccess(string menuId, string roleId)
        {
            try
            {
                UserRoleLogic userRoleLogic = new UserRoleLogic(menuId);
                return userRoleLogic.DeleteRoleAccess(menuId, roleId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }







    }
}